Just so you know, we don't know the file format for every file. If it's just a bunch of random characters, it's probably a .zip or .jar.
Options:
max_damage: 50
max_fire_rate: 20
max_reload_time: 20
max_mag_size: 1000
max_rounds_per_shot: 10
max_range: 50
function updateWeapons():
loop {weapons::*}:
delete {weapon::%loop-value%::*}
delete {weapons::*}
delete {ammos::*}
# Weapon Initialization Arguments:
# Weapon name (unique), Item, Damage, Fire Rate (ticks), Reload Time (seconds), Magazine Size, Rounds Per Shot, Range
# ID (name) # Item # Damage # Fire Rate # Reload Time # Mag size # Rounds / shot # Range
weapon("Instant", bedrock, 20, 4, 8, 50, 1, 40)
weapon("Lightning", gold ingot, 10, 8, 1, 80, 1, 20)
weapon("Zap", diamond, 1, 1, 1, 100, 1, 30)
weapon("Line", redstone dust, 15, 4, 2, 20, 1, 20)
weapon("Helix", nether quartz, 4, 4, 8, 10, 1, 30)
weapon("Dual Helix", popped chorus fruit, 15, 4, 2, 60, 1, 40)
weapon("Circle", blaze rod, 50, 16, 8, 40, 1, 50)
weapon("Control", ender pearl, 10, 4, 9, 1, 1, 50)
weapon("Triple Sweep", stone sword, 1, 4, 5, 100, 1, 30)
function fireWeapon(p: player, id: string, handVec: vector, headVec: vector):
set {_range} to getWeaponData(tool of {_p}, "range")
set {_world} to world of {_p}
if {_id} = "Instant":
set {_pVec} to vector from yaw yaw of {_p} and pitch pitch of {_p}
set standard length of {_pVec} to 0.01
while standard length of {_pVec} < {_range}:
set {_loc} to getLocation({_handVec} ++ {_pVec}, {_world})
if block at {_loc} is solid:
exit 2 sections
set {_tmp::*} to entities in radius 2 of {_loc}
remove {_p} from {_tmp::*}
loop {_tmp::*}:
set {_targets::%loop-value%} to loop-value
add 0.1 to standard length of {_pVec}
play soul fire flame at {_loc}
loop {_targets::*}:
inflictDamage(loop-value, {_p}, {weapon::%{_id}%::damage})
# projectile hit at {_loc}
# example:
# create explosion with power 3 at {_loc}
if {_id} = "Lightning":
set {_pVec} to vector from yaw yaw of {_p} and pitch pitch of {_p}
set standard length of {_pVec} to 0.01
set {_angVec} to {_handVec}
while standard length of {_angVec} -- {_handVec} < {_range}:
loop 20 times:
set {_loc} to getLocation({_angVec} ++ {_pVec}, {_world})
if block at {_loc} is solid:
exit 3 sections
set {_tmp::*} to entities in radius 2 of {_loc}
remove {_p} from {_tmp::*}
loop {_tmp::*}:
set {_targets::%loop-value-2%} to loop-value-2
play angry villager at {_loc}
add 0.2 to standard length of {_pVec}
set {_angVec} to vector of {_loc}
set {_rotVecV} to {_pVec}
subtract 90 from pitch of {_rotVecV}
set {_rotVecH} to {_pVec}
subtract 90 from yaw of {_rotVecH}
rotate {_pVec} around {_rotVecV} by random integer between -90 and 90
rotate {_pVec} around {_rotVecH} by random integer between -90 and 90
set standard length of {_pVec} to 0.01
loop {_targets::*}:
inflictDamage(loop-value, {_p}, {weapon::%{_id}%::damage})
# projectile hit at {_loc}
if {_id} = "Zap":
set {_vel} to vector from yaw yaw of {_p} and pitch pitch of {_p}
set {_pVec} to {_vel}
set standard length of {_pVec} to 0.01
set {_rotVecV} to {_pVec}
subtract 90 from pitch of {_rotVecV}
set {_rotVecH} to {_pVec}
subtract 90 from yaw of {_rotVecH}
set {_angVec} to {_handVec}
while standard length of {_angVec} -- {_handVec} < {_range}:
loop 20 times:
set {_loc} to getLocation({_angVec} ++ {_pVec}, {_world})
if block at {_loc} is solid:
exit 3 sections
set {_tmp::*} to entities in radius 2 of {_loc}
remove {_p} from {_tmp::*}
loop {_tmp::*}:
set {_targets::%loop-value-2%} to loop-value-2
play end rod at {_loc}
add 0.2 to standard length of {_pVec}
set {_angVec} to vector of {_loc}
set {_pVec} to {_vel}
rotate {_pVec} around {_rotVecV} by random integer between -20 and 20
rotate {_pVec} around {_rotVecH} by random integer between -20 and 20
set standard length of {_pVec} to 0.01
loop {_targets::*}:
inflictDamage(loop-value, {_p}, {weapon::%{_id}%::damage})
# projectile hit at {_loc}
if {_id} = "Line":
set {_pVec} to vector from yaw yaw of {_p} and pitch pitch of {_p}
set standard length of {_pVec} to 0.01
while standard length of {_pVec} < {_range}:
set {_loc} to getLocation({_handVec} ++ {_pVec}, {_world})
if block at {_loc} is solid:
exit 2 sections
set {_tmp::*} to entities in radius 2 of {_loc}
remove {_p} from {_tmp::*}
loop {_tmp::*}:
if {_hurt::*} does not contain uuid of loop-value:
inflictDamage(loop-value, {_p}, {weapon::%{_id}%::damage})
add uuid of loop-value to {_hurt::*}
play sonic boom at {_loc}
add 1 to standard length of {_pVec}
wait 1 tick
# projectile hit at {_loc}
if {_id} = "Helix":
set {_rotVec} to vector from yaw yaw of {_p} and pitch pitch of {_p}
set standard length of {_rotVec} to 0.01
set {_pVec} to {_rotVec}
subtract 90 from pitch of {_pVec}
set standard length of {_pVec} to 1
while standard length of {_rotVec} ++ {_pVec} < {_range}:
set {_loc} to getLocation({_handVec} ++ {_rotVec} ++ {_pVec}, {_world})
if block at {_loc} is solid:
exit 2 sections
set {_tmp::*} to entities in radius 2 of {_loc}
remove {_p} from {_tmp::*}
loop {_tmp::*}:
if {_hurt::*} does not contain uuid of loop-value:
inflictDamage(loop-value, {_p}, {weapon::%{_id}%::damage})
add uuid of loop-value to {_hurt::*}
play heart at {_loc}
rotate {_pVec} around {_rotVec} by 30
add 0.5 to standard length of {_rotVec}
wait 1 tick
# projectile hit at {_loc}
if {_id} = "Dual Helix":
set {_rotVec} to vector from yaw yaw of {_p} and pitch pitch of {_p}
set standard length of {_rotVec} to 0.01
set {_pVec} to {_rotVec}
subtract 90 from pitch of {_pVec}
set standard length of {_pVec} to 1
while standard length of {_rotVec} ++ {_pVec} < {_range}:
loop 2 times:
set {_loc} to getLocation({_handVec} ++ {_rotVec} ++ {_pVec}, {_world})
if block at {_loc} is solid:
exit 3 sections
set {_tmp::*} to entities in radius 2 of {_loc}
remove {_p} from {_tmp::*}
loop {_tmp::*}:
if {_hurt::*} does not contain uuid of loop-value-2:
inflictDamage(loop-value-2, {_p}, {weapon::%{_id}%::damage})
add uuid of loop-value-2 to {_hurt::*}
play squid ink at {_loc}
rotate {_pVec} around {_rotVec} by 180
rotate {_pVec} around {_rotVec} by 30
add 0.5 to standard length of {_rotVec}
wait 1 tick
# projectile hit at {_loc}
if {_id} = "Circle":
set {_rotVec} to vector from yaw yaw of {_p} and pitch pitch of {_p}
set standard length of {_rotVec} to 0.01
set {_pVec} to {_rotVec}
subtract 90 from pitch of {_pVec}
set standard length of {_pVec} to random number between 0.3 and 0.7
while standard length of {_rotVec} ++ {_pVec} < {_range}:
loop 36 times:
set {_loc} to getLocation({_handVec} ++ {_rotVec} ++ {_pVec}, {_world})
if block at {_loc} is solid:
exit 3 sections
set {_tmp::*} to entities in radius 2 of {_loc}
remove {_p} from {_tmp::*}
loop {_tmp::*}:
if {_hurt::*} does not contain uuid of loop-value-2:
inflictDamage(loop-value-2, {_p}, {weapon::%{_id}%::damage})
add uuid of loop-value-2 to {_hurt::*}
play flame at {_loc}
rotate {_pVec} around {_rotVec} by 10
rotate {_pVec} around {_rotVec} by 30
set standard length of {_pVec} to random number between 0.3 and 0.7
add 1 to standard length of {_rotVec}
wait 1 tick
# projectile hit at {_loc}
if {_id} = "Control":
set {_rotVec} to vector from yaw yaw of {_p} and pitch pitch of {_p}
set standard length of {_rotVec} to 0.01
set {_pVec} to {_rotVec}
subtract 90 from pitch of {_pVec}
set standard length of {_pVec} to 0.2
while standard length of {_rotVec} ++ {_pVec} < {_range}:
set {_eyeVec} to vector of head location of {_p}
add 0.5 to {_len}
loop 36 times:
set {_loc} to getLocation({_eyeVec} ++ {_rotVec} ++ {_pVec}, {_world})
if block at {_loc} is solid:
exit 3 sections
set {_tmp::*} to entities in radius 2 of {_loc}
remove {_p} from {_tmp::*}
loop {_tmp::*}:
if {_hurt::*} does not contain uuid of loop-value-2:
inflictDamage(loop-value-2, {_p}, {weapon::%{_id}%::damage})
add uuid of loop-value-2 to {_hurt::*}
play glow at {_loc}
rotate {_pVec} around {_rotVec} by 10
set yaw of {_rotVec} to yaw of {_p}
set pitch of {_rotVec} to pitch of {_p}
set standard length of {_rotVec} to {_len}
rotate {_pVec} around {_rotVec} by 30
wait 1 tick
# projectile hit at {_loc}
if {_id} = "Triple Sweep":
set {_rotVec} to vector from yaw yaw of {_p} and pitch pitch of {_p}
set standard length of {_rotVec} to 0.01
loop 3 times:
add {_rotVec} to {_pVec::*}
subtract 90 from pitch of {_rotVec}
set {_degrees} to -9
set {_cone} to abs({_degrees}) * 2
loop {_pVec::*}:
rotate {_pVec::%loop-index%} around {_rotVec} by {_degrees}
set {_degrees} to {_degrees} + {_cone} / ((size of {_pVec::*}) - 1)
while standard length of random element out of {_pVec::*} < {_range}:
if size of {_pVec::*} = {_reloadtime}:
set {_ammo} to getWeaponData(tool of {_p}, "mag_size")
setWeaponData({_p}, "ammo", {_ammo})
set name of tool of {_p} to formatWeaponName(getWeaponId(tool of {_p}), getWeaponData(tool of {_p}, "ammo"))
exit 2 sections
wait 1 tick
add 1 to {_reload}
send action bar "" to {_p}
resetTags({_p}, "reloading")
resetTags({_p}, "cd")
function removeAmmo(weapon: item, p: player):
set {_id} to getWeaponId(tool of {_p})
setWeaponData({_p}, "ammo", getWeaponData(tool of {_p}, "ammo") - getWeaponData(tool of {_p}, "rounds_per_shot"))
set name of tool of {_p} to formatWeaponName(getWeaponId(tool of {_p}), getWeaponData(tool of {_p}, "ammo"))
function resetTags(p: player, tag: string):
loop inventory of {_p}:
if isWeapon(loop-value) = true:
set {_nbt} to nbt compound of loop-value
set tag {_tag} of {_nbt} to 0
set {_weapon} to loop-value with nbt {_nbt}
set {_slot} to index of loop-value
set slot {_slot} of {_p} to {_weapon}
function getLocation(vec: vector, world: world) :: location:
return location at (x component of {_vec}, y component of {_vec}, z component of {_vec}) in world {_world}
function getWeaponId(weapon: item) :: string:
set {_nbt} to nbt compound of {_weapon}
return "%tag "id" of {_nbt}%"
function getWeaponData(weapon: item, data: string) :: integer:
set {_nbt} to nbt compound of {_weapon}
return "%tag {_data} of {_nbt}%" parsed as integer
function setWeaponData(p: player, data: string, value: number):
set {_nbt} to nbt compound of tool of {_p}
set tag {_data} of {_nbt} to {_value}
function isWeapon(weapon: item) :: boolean:
if {weapons::*} contains getWeaponId({_weapon}):
return true
return false
function isReloading(p: player) :: boolean:
if getWeaponData(tool of {_p}, "reloading") = 1:
return true
return false
function getWeaponsInInventory(p: player) :: items:
loop inventory of {_p}:
if isWeapon(loop-value) = true:
add loop-value to {_weapons::*}
return {_weapons::*}
function formatWeaponName(name: string, ammo: number) :: string:
set {_name} to {_name} in strict proper case
return "&b%{_name}% &f[&3%{_ammo}%&f]"
function newSerialNumber(id: string) :: integer:
add 1 to {serial::%{_id}%}
return {serial::%{_id}%}
function formatDigits(i: integer, n: integer) :: string:
set {_fill} to ""
loop {_n} - countDigit({_i}) times:
set {_fill} to "0%{_fill}%"
return "%{_fill}%%{_i}%"
function countDigit(n: integer) :: integer:
if {_n} != 0:
return floor(log({_n}) + 1)
return 1
function inflictDamage(victim: entity, attacker: entity, dmg: number):
set {_total} to {_dmg}
damage {_victim} by {_total}
function reloadBar(i: integer) :: strings:
if {_i} 3:
set {_block} to "&6█"
if {_i} > 6:
set {_block} to "&e█"
if {_i} > 9:
set {_block} to "&a█"
add {_block} to {_bar::*}
loop 10 - size of {_bar::*} times:
add "&8█" to {_bar::*}
set {_bar} to "%{_bar::1}%%{_bar::2}%%{_bar::3}%%{_bar::4}%%{_bar::5}%%{_bar::6}%%{_bar::7}%%{_bar::8}%%{_bar::9}%%{_bar::10}%"
return {_bar}
function statsBar(i: integer) :: strings:
if {_i} 3:
set {_block} to "&e▔"
if loop-value > 6:
set {_block} to "&6▔"
if loop-value > 9:
set {_block} to "&c▔"
add {_block} to {_bar::*}
loop 10 - size of {_bar::*} times:
add "&8▔" to {_bar::*}
set {_bar} to "%{_bar::1}%%{_bar::2}%%{_bar::3}%%{_bar::4}%%{_bar::5}%%{_bar::6}%%{_bar::7}%%{_bar::8}%%{_bar::9}%%{_bar::10}%"
return {_bar}
on right click:
set {_p} to event-player
set {_weapon} to tool of {_p}
if isWeapon({_weapon}) is false:
stop
cancel event
set {_id} to getWeaponId({_weapon})
if getWeaponData({_weapon}, "cd") = 1:
stop
if (getWeaponData({_weapon}, "ammo")) |